<html>
<head><meta charset="utf-8"><title>query weird behavior · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/query.20weird.20behavior.html">query weird behavior</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="244431662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/query%20weird%20behavior/near/244431662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> fee1-dead <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/query.20weird.20behavior.html#244431662">(Jun 30 2021 at 14:29)</a>:</h4>
<p>I have been tracking down an issue and I just don't know why a query would return <code>false</code> when it should return <code>true</code>.</p>
<p>I was working on <code>const_trait_impl</code>, where I added a test that tests cross-crate behavior. I have added a test for when the feature is disabled, but when I added another case where the user of the auxiliary crate (of <code>impl const</code>) <em>has</em> the feature enabled, it errors:</p>
<div class="codehilite"><pre><span></span><code>error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
  --&gt; src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs:16:5
   |
16 |     Const.func();
   |     ^^^^^^^^^^^^
</code></pre></div>
<p>I added some debug output to test the logic, and here is the log from building the auxiliary crate:</p>
<div class="codehilite"><pre><span></span><code>&gt; RUSTC_LOG=&quot;rustc_mir::transform::check_consts,rustc_mir::const_eval&quot; build/x86_64-unknown-linux-gnu/stage1/bin/rustc --crate-type rlib src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs

DEBUG rustc_mir::const_eval::fn_queries is_const_fn_raw((...)kind: Fn(FnSig { header: FnHeader { unsafety: Normal, constness: NotConst, (...)
DEBUG rustc_mir::const_eval::fn_queries is_const_impl_raw(def_id=DefId(0:7 ~ cross_crate[8787]::{impl#0}),(...) kind: Impl(Impl { unsafety: Normal, polarity: &quot;positive&quot;, defaultness: Final, defaultness_span: None, constness: NotConst(...)
DEBUG rustc_mir::const_eval::fn_queries is_const_fn_raw((...)kind: Fn(FnSig { header: FnHeader { unsafety: Normal, constness: NotConst,(...)
DEBUG rustc_mir::const_eval::fn_queries is_const_impl_raw(def_id=DefId(0:11 ~ cross_crate[8787]::{impl#1}),(...)kind: Impl(Impl { unsafety: Normal, polarity: &quot;positive&quot;, defaultness: Final, defaultness_span: None, constness: Const,(...)

-snip-
</code></pre></div>
<p>Basically, the first impl  is not <code>const</code>, but the second is. Below is the log when compiling the test file:</p>
<div class="codehilite"><pre><span></span><code>&gt; RUSTC_LOG=&quot;rustc_mir::transform::check_consts,rustc_mir::const_eval&quot; build/x86_64-unknown-linux-gnu/stage1/bin/rustc --extern cross_crate=libcross_crate.rlib src/test/ui/rfc-2632-const-trait-impl/cross-crate-feature-enabled.rs

├─0ms DEBUG rustc_mir::transform::check_consts::validation callee: DefId(19:8 ~ cross_crate[8787]::{impl#0}::func)
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants

-snip-

├─0ms DEBUG rustc_mir::transform::check_consts::validation callee: DefId(19:12 ~ cross_crate[8787]::{impl#1}::func)
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants

-snip-
</code></pre></div>
<p>in this log, the <code>callee</code> variable will be checked with: (the only way that it would emit that error)</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">                </span><span class="k">if</span><span class="w"> </span><span class="o">!</span><span class="n">tcx</span><span class="p">.</span><span class="n">is_const_fn_raw</span><span class="p">(</span><span class="n">callee</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="bp">self</span><span class="p">.</span><span class="n">check_op</span><span class="p">(</span><span class="n">ops</span>::<span class="n">FnCallNonConst</span><span class="p">);</span><span class="w"></span>
<span class="w">                    </span><span class="k">return</span><span class="p">;</span><span class="w"></span>
<span class="w">                </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>However, I get no logging output from <code>is_const_fn_raw</code> and on, so I think it must be using some cache on disk.<br>
I am not familiar with the query system, so it would be great if someone can tell me if this has been reported before, or this is not related to the query (although I am 99% sure that nothing went wrong other than the query part)</p>



<a name="244438502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/query%20weird%20behavior/near/244438502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/query.20weird.20behavior.html#244438502">(Jun 30 2021 at 15:08)</a>:</h4>
<p>For an external crate, the query is implemented here: <a href="https://github.com/rust-lang/rust/blob/5d34076975cd7661dca4e40e0c66a646a78ad091/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs#L127">https://github.com/rust-lang/rust/blob/5d34076975cd7661dca4e40e0c66a646a78ad091/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs#L127</a></p>



<a name="244438565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/query%20weird%20behavior/near/244438565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/query.20weird.20behavior.html#244438565">(Jun 30 2021 at 15:09)</a>:</h4>
<p>which calls this method: <a href="https://github.com/rust-lang/rust/blob/5d34076975cd7661dca4e40e0c66a646a78ad091/compiler/rustc_metadata/src/rmeta/decoder.rs#L1494">https://github.com/rust-lang/rust/blob/5d34076975cd7661dca4e40e0c66a646a78ad091/compiler/rustc_metadata/src/rmeta/decoder.rs#L1494</a></p>



<a name="244442773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/query%20weird%20behavior/near/244442773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> fee1-dead <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/query.20weird.20behavior.html#244442773">(Jun 30 2021 at 15:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125294">Aaron Hill</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/query.20weird.20behavior/near/244438502">said</a>:</p>
<blockquote>
<p>For an external crate, the query is implemented here: <a href="https://github.com/rust-lang/rust/blob/5d34076975cd7661dca4e40e0c66a646a78ad091/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs#L127">https://github.com/rust-lang/rust/blob/5d34076975cd7661dca4e40e0c66a646a78ad091/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs#L127</a></p>
</blockquote>
<p>Thanks, I have found the issue to be how this is encoded.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>